package com.tzy.dishes.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tzy.common.entity.DishesType;
import com.tzy.dishes.mapper.DishesTypeMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
/**
 * <p>
 * 菜品分类表 服务实现类
 * </p>
 * @author 谭同学
 * @since 2022-03-08
 */
@Service
public class DishesTypeService extends ServiceImpl<DishesTypeMapper, DishesType> implements IDishesTypeService {
    @Resource
    private DishesTypeMapper dishesTypeMapper;
    @Override
    @Transactional( rollbackFor = {Exception.class} )//开启事务,遇到异常就回滚
    @CacheEvict(value = {"page","list"},allEntries = true)
    public boolean updateById(DishesType entity) {
        return super.updateById(entity);
    }
    @Cacheable(cacheNames = "list")
    public Page<DishesType> getPage(Page<DishesType> page,QueryWrapper<DishesType> queryWrapper){
        return dishesTypeMapper.selectPage(page,queryWrapper);
    }
    /**
     * 查询所有
     */
    @Cacheable(cacheNames = "list")
    public List<DishesType> list(QueryWrapper<DishesType> queryWrapper) {
        return super.list(queryWrapper);
    }
}
